package com.college.controller.resource;


import com.college.common.pojo.ao.Notice;
import com.college.common.pojo.ao.Notice;
import com.college.common.pojo.dto.resource.AddNoticeDTO;
import com.college.common.pojo.dto.resource.QueryNoticeDTO;
import com.college.common.pojo.dto.resource.UpdateNoticeDTO;
import com.college.common.pojo.model.page.PageParamRequest;
import com.college.common.response.CommonPage;
import com.college.common.response.CommonResult;
import com.college.common.utils.object.ObjectUtil;
import com.college.resource.service.NoticeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 公告 前端控制器
 * @author 小C工作室
 * @since 2025-02-22
 */
@RestController
@RequestMapping("/notice")
@Api(tags = "公告")
@Slf4j
public class NoticeController {

    @Autowired
    private NoticeService noticeService;

    @ApiOperation(value = "查询公告列表")
    @GetMapping(value = "/query-list")
    public CommonResult<List<Notice>> queryList(QueryNoticeDTO queryNoticeDTO) {
        return CommonResult.success(noticeService.queryList(queryNoticeDTO));
    }

    @ApiOperation(value = "查询公告列表分页")
    @GetMapping(value = "/query-list-page")
    public CommonResult<CommonPage<Notice>> queryListPage(QueryNoticeDTO queryNoticeDTO , PageParamRequest pageParamRequest) {
        return CommonResult.success(CommonPage.restPage(noticeService.queryListPage(queryNoticeDTO,pageParamRequest)));
    }

    @ApiOperation(value = "新增公告")
    @PostMapping(value = "/add")
    public CommonResult<String> addNotice(@RequestBody AddNoticeDTO addNoticeDTO) {
        return noticeService.addNotice(addNoticeDTO);
    }

    @ApiOperation(value = "删除公告")
    @DeleteMapping(value = "/delete/{id}")
    public CommonResult<Boolean> deleteNotice(@PathVariable Long id) {
        return CommonResult.success(noticeService.removeById(id));
    }

    @ApiOperation(value = "批量删除公告")
    @DeleteMapping(value = "/batch-delete")
    public CommonResult<Boolean> deleteNotice(@RequestBody List<Long> ids) {
        if (ObjectUtil.isNotEmpty(ids)) {
            return CommonResult.success(noticeService.removeByIds(ids));
        }
        return CommonResult.success("参数错误");
    }

    @ApiOperation(value = "更新公告")
    @PutMapping(value = "/update")
    public CommonResult<String> updateNotice(@RequestBody UpdateNoticeDTO updateNoticeDTO) {
        return noticeService.updateNotice(updateNoticeDTO);
    }
}

